package org.ch00.test08;

/**
 * @author XCH
 * @date 2025 - 03 - 07 - 15:56
 */
public class ProgressThread extends Thread {
    private FileCopyThread fileCopyThread;

    public ProgressThread(FileCopyThread fileCopyThread) {
        this.fileCopyThread = fileCopyThread;
    }

    @Override
    public void run() {
        try {
            while (fileCopyThread.getCopiedBytes() < fileCopyThread.getTotalBytes()) {
                long copiedBytes = fileCopyThread.getCopiedBytes();
                long totalBytes = fileCopyThread.getTotalBytes();
                int progress = (int) ((copiedBytes * 100) / totalBytes);
                System.out.println("拷贝进度: " + progress + "%");
                Thread.sleep(5);  // 每5毫秒打印一次进度
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}